﻿Public Class BLprotocolo

    Private Protocolo As New BEprotocolos
    Private Criterio As New BEcriterioProtocolo
    Private Equipo As New BEequipo
    Private DAOprotocolo As New DAprotocolo

    Private Function valida()
        Return True
    End Function


    Public Function Buscar(ByVal codProtocolo As String, ByVal nombre As String, ByVal codPatrocinador As Integer, ByVal codResponsable As Integer, _
                           ByVal fecini As Date, ByVal fecfin As Date, ByVal tipoprotocolo As Integer, ByVal estado As Integer)

        Dim icodProtocolo = 0
        If codProtocolo <> Nothing Then
            Try
                icodProtocolo = Integer.Parse(codProtocolo)
            Catch ex As Exception
                MsgBox(ex.ToString)
            End Try
        End If

        Return DAOprotocolo.Buscar(icodProtocolo, nombre, codPatrocinador, codResponsable, fecini, fecfin, _
                                   tipoprotocolo, estado)
    End Function

    Public Function ListarTipoProtocolo() As System.Linq.IQueryable(Of BTTsoft.tipo_protocolo)

        Return DAOprotocolo.ListarTipoProtocolo

    End Function

    Public Function ListarEstados() As System.Linq.IQueryable(Of BTTsoft.estado_protocolo)

        Return DAOprotocolo.ListarEstados

    End Function


    Public Sub Guardar(ByVal CodPatrocinador As Integer, ByVal Titulo As String, ByVal Prospectivo As Boolean _
                        , ByVal Retrospectivo As Boolean, ByVal FecIni As Date, ByVal FecFin As Date _
                        , ByVal codInvestigador As Integer, ByVal obs As String, ByVal maxpart As Integer, ByVal minpart As Integer _
                        , ByVal estado As Integer)

        If valida() Then


            Protocolo._titulo = Titulo
            Protocolo._codPatrocinador = CodPatrocinador
            If Prospectivo Then
                Protocolo._codTipo = Constantes.PROSPECTIVO
            End If

            If Retrospectivo Then
                Protocolo._codTipo = Constantes.RETROSPECTIVO
            End If
            Protocolo._codEstado = estado
            Protocolo._fecFin = FecFin
            Protocolo._fecInicio = FecIni
            Protocolo._obs = obs

            If codInvestigador <> Nothing Then
                Equipo._codPersonal = codInvestigador
                Equipo._codRol = Constantes.INVESTIGADOR
            Else
                Me.Equipo = Nothing
            End If

            If maxpart <> Nothing Or minpart <> Nothing Then
                Criterio._valorMax = maxpart
                Criterio._valorMin = minpart
            Else
                Me.Criterio = Nothing
            End If

            DAOprotocolo.Guardar(Me.Protocolo, Me.Criterio, Me.Equipo)
        End If
    End Sub
End Class
